package com.tianzj.boot.mvc.repository.system;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.tianzj.boot.mvc.entity.system.SysUserRole;

public interface SysUserRoleRepository extends JpaRepository<SysUserRole, Long>,JpaSpecificationExecutor<SysUserRole> {

	@Query(value="select role_id from sys_user_role where user_id =?1",nativeQuery=true)
	List<Long> getRoleIdByUserId(Long userId);

	@Transactional
	@Modifying(clearAutomatically=true)
	@Query(value="delete from sys_user_role where user_id =?1",nativeQuery=true)
	void deleteByUserId(Long userId);

	List<SysUserRole> findByUserId(Long userId);

	List<SysUserRole> findByRoleId(Long roleId);


}
